#!./perl -- -*-perl-*-

# ------------------------------------------------------------

# Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
# This is a rewrite of a program that was trashed by our power
# surge in the middle of February 1994.

# ------------------------------------------------------------

# Bugs and other fixes

# March 1, 1994 (Reuven)
# Fixed security hole that could result from people
# executing subshells
# January 5, 1995 (McGredy)
# Modified for Pure Software, Inc.
# ------------------------------------------------------------

# Define fairly-constants
$mailprog = '/usr/ucb/mail -s "PS Web Comment"';
# Ric: Change this to "support@pure.com" when it goes to Test
# Ric: Change this to "ricm@rahul.net" when installed on rahul or mnl
$recipient = 'ricm@rahul.net, info-home@pure.com';

# Print out what we need
print "Content-type: text/html\n\n";
print "<img src=/pure/logo.gif>";
print "<p><hr><p>";
print "<Head><Title>Thank You</Title></Head>";
print "<Body><H1>Thank you for your comments.</H1>";

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    # Stop people from using subshells to execute commands
    $value =~ s/~!/ ~!/g;

    # Uncomment for debugging purposes
    # print "Setting $name to $value<P>";

    $FORM{$name} = $value;
}

# Now send mail to $recipient

open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "$FORM{'username'}, ($FORM{'realname'}, $FORM{'phonenum'}) sent the 
\
n";
print MAIL "following comment about the Pure Software Web pages:\n\n";
print MAIL  "------------------------------------------------------------\n\n";
print MAIL "$FORM{'comments'}\n";
print MAIL 
"\n------------------------------------------------------------\n\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);


print "<P>";
print "<ul><li>Return to the <A HREF=\"index.html\">Pure Software Inc. Home 
Page
 </A>, if you want.</ul><P><hr>";
print "<p>Your comments have been forwarded to the Customer Support department 
(
<code>support@pure.com</code>) at Pure Software Inc.";

